//图书销量排行榜前十，横柱状图

(function (){
    //实例化对象
    var chartDom = document.querySelector('.bookname .chart');
    var myChart = echarts.init(chartDom);
    var option;
    //指定项配置数据
    const data = [];
for (let i = 0; i < 5; ++i) {
  data.push(Math.round(Math.random() * 200));
}
option = {
    color: ["#3398DB"],
    xAxis: {
     max: 'dataMax',

        //不显示x坐标轴：
        axisLine:{
            show: false
        }
    },
    //修改图标大小
    grid: {
                left: '5%',
                right: '5%',
                top: '15%',
                bottom: '10%',
                containLabel: true
            },
    yAxis: {
        data: ['A', 'B', 'C', 'D', 'E'],
        animationDuration: 300,
        animationDurationUpdate: 300,
        //修改刻度标签相关样式
        axisLabel:{
            show:true
        },
        axisLine:{
            show: false
        }
    },
    series: [
        {
         realtimeSort: true,
         type: 'bar',
            data: data,
          label: {
           show: true,
           position: 'right',
           valueAnimation: true
         }
       }
     ],
     legend: {
        show: true
    },
    animationDuration: 0,
    animationDurationUpdate: 3000,
    animationEasing: 'linear',
    animationEasingUpdate: 'linear'
};
function run() {
  for (var i = 0; i < data.length; ++i) {
    if (Math.random() > 0.9) {
      data[i] += Math.round(Math.random() * 2000);
    } else {
      data[i] += Math.round(Math.random() * 200);
    }
  }
  myChart.setOption({
    series: [
      {
        type: 'bar',
        data
      }
    ]
  });
}
setTimeout(function () {
  run();
}, 0);
setInterval(function () {
  run();
}, 3000);

myChart.setOption(option);
//让图表随屏幕自适应
    window.addEventListener("resize",function (){
        myChart.resize();
    })
})();
